package com.atguigu.eduSta.schedule;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import com.atguigu.eduSta.service.StatisticsDailyService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author Summerday
 */
@Component
public class ScheduleTask {

    @Resource
    private StatisticsDailyService statisticsDailyService;

    @Scheduled(cron = "0 0 1 * * ?")//每天凌晨一点
    public void createDataTask(){
        //获取前一天的时间,并且转为yyyy-MM-dd形式
        DateTime yesterday = DateUtil.yesterday();
        String date = DateUtil.format(yesterday, DatePattern.NORM_DATE_PATTERN);
        statisticsDailyService.registerCount(date);

    }
}
